﻿<div class="layui-fluid" style="padding-bottom: 0;">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md2">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 10px;">
                    <!-- 左侧树栏目 -->
                    <div id="BenchTree" style="height: calc(100vh - 150px)"></div>
                </div>
            </div>
        </div>
        <div class="layui-col-md10">
            <div class="layui-card">
                <div class="layui-card-body" style="padding: 10px;">
                    <!-- 右侧表格 -->
                    <form class="layui-form toolbar">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">KeyWord:</label>
                                <div class="layui-input-inline">
                                    <input id="keyword" class="layui-input" placeholder="BenchNo/BenchName/KeyParam/BenchModel/Remark" />
                                </div>
                            </div>
                            <!--<div class="layui-inline">
                                <label class="layui-form-label">ItemCode:</label>
                                <div class="layui-input-inline">
                                    <input id="dictDataCode" class="layui-input" placeholder="Plaese Input ItemCode"/>
                                </div>
                            </div>-->
                            <div class="layui-inline">
                                &emsp;
                                <button class="layui-btn icon-btn" lay-filter="BenchTbSearch" lay-submit>
                                    <i class="layui-icon">&#xe615;</i>Search
                                </button>
                            </div>
                        </div>
                    </form>
                    <!-- 数据表格2 -->
                    <table id="BenchTb" lay-filter="BenchTb"></table>
                </div>
            </div>
        </div>
    </div>
</div>

<script>

    layui.use(['layer', 'form', 'table', 'util', 'admin', 'setter','tree'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var util = layui.util;
        var admin = layui.admin;
        var setter = layui.setter;
        var tree = layui.tree;
        var searchjson = {};

        /* 渲染表格 */
        var insTb = table.render({
            elem: '#BenchTb',
            method: 'post',
            headers: { 'Authorization': setter.getToken() },
            contentType: 'application/json',
            url: layui.setter.appServer + 'Resource_Bench/GetList',
            height: 'full-200',
            page: {
                limit: 50,
                limits: [20, 50, 100, 200],
                groups: 10
            },
            toolbar: ['<p>',
                '<button lay-event="add" class="layui-btn layui-btn-sm icon-btn"><i class="layui-icon">&#xe654;</i>add</button>&nbsp;',
                //'<button lay-event="edit" class="layui-btn layui-btn-sm layui-btn-warm icon-btn"><i class="layui-icon">&#xe642;</i>edit</button>&nbsp;',
                '<button lay-event="del" class="layui-btn layui-btn-sm layui-btn-danger icon-btn"><i class="layui-icon">&#xe640;</i>del</button>',
                '</p>'].join(''),
            defaultToolbar: [],
            cols: [[
                { type: 'numbers' },
                { field: 'BenchNo', title: 'BenchNo', width: 160 },
                { field: 'BenchName', title: 'BenchName', width: 200 },
                { field: 'KeyParam', title: 'KeyParam', width: 200 },
                { field: 'BenchModel', title: 'Model', width: 150 },
                { field: 'ResponserName', title: 'Responser', width: 150 },
                {
                    field: 'BenchStatus', title: 'BenchStatus', width: 150, templet: function (d) {
                        return '后续台架对接'
                    }
                },
                { field: 'CreateUserName', title: 'CreateUser', width: 150 },
                {
                    field: 'CreateDate', title: 'CreateDate', width: 150, templet: function (d) {
                        return moment(d.CreateDate).format('YYYY-MM-DD HH:mm')
                    }
                }
            ]],
            done: function (res, curr, count) {
                //console.log(res)
            }
        });

        table.on('toolbar(BenchTb)', function (obj) {
            if (obj.event == 'add') {
                admin.open({
                    type: 1,
                    offset: '0px',
                    area: [$(window).width() + 'px', $(window).height() + 'px'],
                    title: 'AddTestBench',
                    data: { insTb: insTb, seeType: 1, treeRender: treender },
                    url: 'components/equip/bench/edit.html',
                    success: function (bzlayero, bzdIndex) {
                        //layer.full(bzdIndex);
                    }
                });
            }
        });
        table.on('rowDouble(BenchTb)', function (obj) {
            admin.open({
                type: 1,
                offset: '0px',
                area: [$(window).width() + 'px', $(window).height() + 'px'],
                title: 'EditTestBench',
                data: { insTb: insTb, seeType: 2, treeRender: treender,Id:obj.data.Id },
                url: 'components/equip/bench/edit.html',
                success: function (bzlayero, bzdIndex) {
                    //layer.full(bzdIndex);
                }
            });
        });
        /* 渲染左侧树 */
        var treender = function () {
            var loadIndex = layer.load(2);
            admin.req(setter.appServer + "Resource_Bench/GetTreeData", JSON.stringify({}), function (res) {
                layer.close(loadIndex);
                if (res.code === 0) {
                    tree.render({
                        elem: '#BenchTree',
                        data: res.data,
                        showCheckbox: false,  // 是否显示复选框
                        onlyIconControl: true,  // 是否仅允许节点左侧图标控制展开收缩
                        accordion: true,
                        showLine: true,
                        id: 'BenchTree',
                        isJump: true, // 是否允许点击节点时弹出新窗口跳转
                        click: function (obj) {
                            
                            $('#BenchTree').find('.layui-tree-txt').removeClass('lefttreeclick');
                            $(obj.elem).find('.layui-tree-txt:eq(0)').addClass('lefttreeclick');

                            //var data = obj.data;  //获取当前点击的节点数据
                            //layer.msg('状态：' + obj.state + '<br>节点数据：' + JSON.stringify(data));
                            searchjson.BenchType = obj.data.id;
                            insTb.reload({ where: { searchJson: JSON.stringify(searchjson) } },true);
                        }
                    });
                     
                } else {
                    layer.msg(res.msg, { icon: 2 });
                }
            }, 'post');
            return false;
        }
        treender();

        form.on('submit(BenchTbSearch)', function (data) {
            insTb.reload({ where: { searchKey: $('#keyword').val()} },true);
            return false;
        });
    });
</script>